package cn.kgc.vueair.service.impl;

import cn.kgc.vueair.mapper.QualityMapper;
import cn.kgc.vueair.pojo.Quality;
import cn.kgc.vueair.pojo.QualityExample;
import cn.kgc.vueair.service.QualityService;
import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;
import org.springframework.stereotype.Service;

import javax.annotation.Resource;
import java.util.List;

@Service
public class QualityServiceImpl implements QualityService{
    @Resource
    QualityMapper qualityMapper;
    @Override
    public PageInfo<Quality> select(Integer pageNum, Integer pageSize, Integer districtid) {
        PageHelper.startPage(pageNum,pageSize);
        List<Quality> qualityList;
        if(districtid!=0){
            QualityExample example=new QualityExample();
            QualityExample.Criteria criteria=example.createCriteria();
            criteria.andDistrictidEqualTo(districtid);
            qualityList=qualityMapper.selectByExample(example);
        }else {
            qualityList=qualityMapper.selectByExample(null);
        }
        PageInfo<Quality> pageInfo=new PageInfo<>(qualityList);
        return pageInfo;
    }

    @Override
    public Integer add(Quality quality) {
        int i=qualityMapper.insert(quality);
        return i;
    }

    @Override
    public Quality selectById(Integer id) {
        Quality quality=qualityMapper.selectByPrimaryKey(id);
        return quality;
    }

    @Override
    public Integer update(Quality quality) {
        int i=qualityMapper.updateByPrimaryKeySelective(quality);
        return i;
    }

    @Override
    public Integer delete(Integer id) {
        int i=qualityMapper.deleteByPrimaryKey(id);
        return i;
    }
}
